<template>
    <!-- 总承包管理费 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :export-config="{
                        use: true,
                        select: '目标责任书',
                        all: '目标责任书'
                    }"
                :exportPermission="{ select: 'bm_022_exp_03', all: 'bm_022_exp_03' }"
                     :statistics-config="{ use: true,  statistics, temp }"
            >
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'bm_022_loo_02'">查看</a>
                    <span
                    v-if="(record.status == 'DRAFT' || record.status=='REJECTED')&&hideBuquBtn()"
                        v-btnPermission="'bm_022_edi_01'"
                    >
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                        <a @click="handleManage(3, record)" v-if="record.redoExamine == 1">补录</a>
                    <span
                        v-if="
                            record.status === 'PAST' ||
                            record.status === 'SUBMITTED' ||
                            record.status === 'REJECTED' ||
                            record.status === 'ABOLISH'
                        "
                        v-btnPermission="'bm_022_loo_02'"
                    >
                        <approval-button :id="record.id" :status="record.status" />
                    </span>
                    </MoreButton>
                </template>
                <template slot="status" slot-scope="text, record">
                    <list-status :status="record.status" conversion="en" :is-approval="true" :text="text" />
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getTargetList, delTarget } from '@/api/businessAffairs/responsibilityManagement' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { typeListApproval1 } from '@/utils/util'
const searchArr = [
    // 搜索框
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '签订日期',
        type: 'dateRange',
        value: 'signDate',
        attr: {
            rangeFormat: ['signBeginDate', 'signEndDate']
        }
    },
    {
        name: '填报人',
        type: 'input',
        value: 'creatorName'
    },
    {
        name: '填报时间',
        type: 'dateRange',
        value: 'activityDate',
        attr: {
            rangeFormat: ['createTimeBegin', 'createTimeEnd']
        }
    },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: typeListApproval1
    }
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        }
    },
    {
        title: '所属分公司',
        dataIndex: 'companyName'
    },

    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '合同额（万元）',
        dataIndex: 'contractFee'
    },
    {
        title: '自施合同额（万元）',
        dataIndex: 'autoContractFee'
    },
    {
        title: '上缴利润率(%)',
        dataIndex: 'tentativelyUpRate'
    },
    {
        title: '暂定上缴利润额（万元）',
        dataIndex: 'tentativelyUpProfitFee'
    },
    {
        title: '标准成本降低率(%)',
        dataIndex: 'standardCostPofitRate'
    },
    {
        title: '签订日期',
        dataIndex: 'signDate'
    },
    {
        title: '填报人',
        dataIndex: 'fillPeopleName'
    },
    {
        title: '填报时间',
        dataIndex: 'fillDate'
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
        // scopedSlots: { customRender: 'status' }
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        // align: 'center',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        
        return {
            queryParam: {}, // 查询参数
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            statistics: { totalAutoContractFee: 0, totalTentativelyUpProfitFee: 0, totalTentativelyUpRate: 0 }, //统计
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                console.log()
                const [err, res] = await getTargetList(requestParameters)
                res.data.forEach(item => {
                    if(item.status=='PAST'){
                        item.auditStatusName='审批通过'
                    }else if(item.status=='SUBMITTED'){
                        item.auditStatusName='审批中'
                    }else if(item.status=='REJECTED'){
                        item.auditStatusName='审批不通过'
                    }else if(item.status=='DRAFT'){
                        item.auditStatusName='待提交审批'
                    }
                });
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        if (res.data.length > 0) {
                            this.$nextTick(() => {
                                this.statistics.totalAutoContractFee = res.data[0].totalAutoContractFee
                                this.statistics.totalTentativelyUpProfitFee = res.data[0].totalTentativelyUpProfitFee
                                this.statistics.totalTentativelyUpRate = res.data[0].totalTentativelyUpRate
                            })
                        }
                        resolve(res)
                    }
                })
            },
            temp: () => {
            return (
                <span style="margin-right: 12px">
                自施合同额（万元）：<span class="totalNum">{ this.statistics.totalAutoContractFee }  </span> 
                暂定上缴利润额（万元）：<span class="totalNum">{ this.statistics.totalTentativelyUpProfitFee}  </span> 
                上缴利润率(%)：<span class="totalNum">{ this.statistics.totalTentativelyUpRate}  </span> 
                标准成本降低率(%)：：<span class="totalNum">{ this.statistics.totalTentativelyUpRate}  </span> 
                
                </span>
            )
          },
            removeApi: { remove: delTarget, invalid: delTarget, undo: delTarget } // api
        }
    },
    methods: {
        // 搜索
        search(value) {
            // console.log(value,"1111111111111111111111111")
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type === 3 ? 1 : type ,
                t: type === 3 ? 1 : 0
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateTargetBook',
                query
            })
        }
    }
}
</script>
